<template>
  <a-card>
    <a-space class="operator">
      <a-button type="primary">新建</a-button>
      <!-- <a-button >批量操作</a-button> -->
      <a-dropdown>
        <a-menu @click="handleMenuClick" slot="overlay">
          <!-- <a-menu-item key="delete">删除</a-menu-item>
            <a-menu-item key="audit">审批</a-menu-item> -->

          <a-menu-item key="toLead">
            <a-icon type="upload" />导入
            <input
              type="file"
              title=""
              @change="fileChange"
              v-show="false"
              id="upload"
            />
          </a-menu-item>

          <a-menu-item key="toOut">
            <a-icon type="vertical-align-bottom" />导出
          </a-menu-item>
        </a-menu>
        <a-button> 更多操作 <a-icon type="down" /> </a-button>
      </a-dropdown>
    </a-space>
    <!-- <standard-table
        :columns="columns"
        :dataSource="dataSource"
        :selectedRows.sync="selectedRows"
        @clear="onClear"
        @change="onChange"
        @selectedRowChange="onSelectChange"
      >
        <div slot="description" slot-scope="{ text }">
          {{ text }}
        </div>
        <div slot="action" slot-scope="{ text, record }">
        </div>
        <template slot="statusTitle">
          <a-icon @click.native="onStatusTitleClick" type="info-circle" />
        </template>
      </standard-table> -->
    <!-- <div class="table-adv"> -->
    <advance-table
      :columns="columns"
      :data-source="dataSource"
      :title="tableTitle"
      :loading="loading"
      rowKey="id"
      @search="onSearch"
      @refresh="onRefresh"
      :format-conditions="true"
      @reset="onReset"
      :bordered="true"
      :scroll="{ x: 1000 }"
      :pagination="false"
    >
      <!-- <template slot="statusTitle">
        状态<a-icon style="margin: 0 4px" type="info-circle" />
      </template> -->
      <template slot="send" slot-scope="{ text }">
        {{ text ? "是" : "否" }}
      </template>
      <!-- <template slot="status" slot-scope="{ text }">
        {{ text | statusStr }}
      </template> -->
      <template slot="enterpriseName" slot-scope="{ text }">
        {{text.enterpriseName}}<a-tag  style="margin-left:5px" v-show="text.top_time">置顶</a-tag>
      </template>

       <template slot="operation" slot-scope="{text, record}">
        <div class="operation">
        
          <a href="javascript:;">编辑</a>
       
         <a-popconfirm
          v-if="dataSource.length"
          :title="`确定要${text.top_time?'取消':''}置顶吗?`"
          @confirm="() => onTop(record.key)"
        >
       
          <a href="javascript:;" v-show="text.top_time">取消置顶</a>
          <a href="javascript:;" v-show="!text.top_time">置顶</a>

        </a-popconfirm>
        </div>
        </template>
    </advance-table>

    <div class="show-right">
      <a-pagination
        :current="page"
        :pageSize="pageSize"
        :total="total"
        :showSizeChanger="true"
        :showLessItems="true"
        :showQuickJumper="true"
        :pageSizeOptions="['10','20', '50', '100', '500', '']"
        :scroll="{ x: 1300}"
        :showTotal="
          (total, range) => `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`
        "
        @change="onPageChange"
        @showSizeChange="onSizeChange"
      >
        <template slot="buildOptionText" slot-scope="props">
          <span v-if="props.value !== ''">{{ props.value }}条/页</span>
          <span v-else>全部</span>
        </template>
      </a-pagination>
    </div>

    <!-- </div> -->
  </a-card>
</template>

<script>
// import StandardTable from "@/components/table/StandardTable";
import AdvanceTable from "@/components/table/advance/AdvanceTable";
import { teachingUpload, teachingList } from "@/services/teaching-culture";

export default {
  name: "TeachingCulture",
  components: { AdvanceTable },
  filters: {
    statusStr(val) {
      switch (val) {
        case 1:
          return "已下单";
        case 2:
          return "已付款";
        case 3:
          return "已审核";
        case 4:
          return "已发货";
      }
    },
  },
  data() {
    return {
      loading: false, //表格是否加载中
      page: 1, //第几页
      pageSize: 10, //一页多少条
      total: 0, //总共多少条
      tableTitle: " ", //表格标题
      columns: [
        //显示什么列
        {
          title: "公司名称",
          // dataIndex: "enterpriseName",
          slots: { title: "enterpriseName" },
          scopedSlots: { customRender: "enterpriseName" },
          width: 400,
          searchAble: true,
        },
        {
          title: "公司分类",
          dataIndex: "sheetName",
          width: 200,
          searchAble: true,
        },
        {
          title: "注册地址",
          dataIndex: "registeredAddress",
           width: 300,
        },
         {
          title: "经营范围",
          dataIndex: "scopeBusiness",
           width: 150,
        },
         {
          title: "成立日期",
          dataIndex: "setUpDate",
           width: 150,
           dataType: "date"
        },
         {
          title: "核准日期",
          dataIndex: "approvedDate",
           width: 150,
            dataType: "date"
        },
         {
          title: "法人",
          dataIndex: "legalPerson",
           width: 150,
        },
         {
          title: "沟通跟进情况",
          dataIndex: "followUpSituation",
           width: 300,
        },

        // {
        //   // searchAble: true,
        //   dataIndex: "status",
        //   dataType: "select",
        //   slots: { title: "statusTitle" },
        //   scopedSlots: { customRender: "status" },
        //   search: {
        //     selectOptions: [
        //       { title: "已下单", value: 1 },
        //       { title: "已付款", value: 2 },
        //       { title: "已审核", value: 3 },
        //       { title: "已发货", value: 4 },
        //     ],
        //   },
        // },
        // {
        //   title: "发货",
        //   // searchAble: true,
        //   dataIndex: "send",
        //   dataType: "boolean",
        //   scopedSlots: { customRender: "send" },
        //   search: {
        //     switchOptions: {
        //       checkedText: "开",
        //       uncheckedText: "关",
        //     },
        //   },
        // },
        // {
        //   title: "审核时间",
        //   dataIndex: "auditTime",
        //   dataType: "time",
        // },
        {
          title: "操作",
          fixed: "right",
          notSearch:true,
           width: 130,
          scopedSlots: { customRender: "operation" },
        },
      ],
      dataSource: [], //显示的数据
      conditions: {}, //条件
    };
  },
  authorize: {
    deleteRecord: "delete",
  },
  created() {
    // this.getColumns()
    this.tableLoad();
  },
  methods: {
    onSearch(conditions, searchOptions) {
      //console.log(searchOptions);
      //console.log(conditions);
      this.page = 1;
      this.conditions = conditions;
      this.tableLoad();
    },
    onSizeChange(current, size) {
      this.page = 1;
      this.pageSize = size;
      this.tableLoad();
    },
    onRefresh(conditions) {
      this.conditions = conditions;
      this.tableLoad();
    },
    onReset(conditions) {
      this.conditions = conditions;
      this.tableLoad();
    },
    onPageChange(page, pageSize) {
      // alert()
      this.page = page;
      this.pageSize = pageSize;
      this.tableLoad();
    },

    fileChange(e) {
      const { uploading, $message } = this;
      let files = e.target.files[0];
      let formData = uploading(files, "excel", "teaching_culture");
      if (formData) {
        //  teachingUpload
        this.$confirm({
          title: "确定要导入吗?",
          // content: 'When clicked the OK button, this dialog will be closed after 1 second',
          onOk() {
            $message.loading({ content: "导入中", key: "loading" });
            teachingUpload(formData)
              .then((res) => {
                if (res.code == 200) {
                  $message.success({
                    content: "导入成功",
                    key: "loading",
                    duration: 2,
                  });
                } else {
                  $message.error({
                    content: "导入失败",
                    key: "loading",
                    duration: 2,
                  });
                }
              })
              .catch((error) => {
                $message.error({
                  content: "导入失败",
                  key: "loading",
                  duration: 2,
                });
              });
          },
        });

        var file = document.getElementById("upload");
        file.value = ""; //重置了file的outerHTML
      }
      // //console.log(formData);
    },

    getColumns() {
      this.columns = [];
    },

    async tableLoad() {
      this.loading = true;
      const {page,pageSize} = this
      let teaching=   await teachingList({page:page,pageSize:pageSize,keyWord:{}})
      //console.log(teaching);
      const { list, total } = teaching.data;
      //console.log(list);
      this.dataSource = list;
      this.total = total;
      this.loading = false;

    },

    handleMenuClick(e) {
      if (e.key === "toLead") {
        //导入
        let upload = document.getElementById("upload");

        upload.click();
      }
    },
  },
};
</script>

<style lang="less" scoped>
.table-adv {
  max-width: 100%;
  // border: 1px solid blue;
  overflow: auto;
  white-space: nowrap;
}

.show-right {
  float: right;
  margin-top: 10px;
}
.operation{
  display: flex;
  justify-content: space-between;
}
</style>
